package com.erp.erp_servers.CarryPlan.Imp;

import com.erp.erp_dao.CarryPlan.CarryPlanProductDao;
import com.erp.erp_entitys.CarryPlan.CarryPlan;
import com.erp.erp_entitys.CarryPlan.CarryPlanProduct;
import com.erp.erp_servers.CarryPlan.CarryPlanProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出运计划产品明细表(CarryPlanProduct)表服务实现类
 *
 * @author makejava
 * @since 2020-10-15 23:30:14
 */
@Service("carryPlanProductService")
public class CarryPlanProductServiceImpl implements CarryPlanProductService {
    @Resource
    private CarryPlanProductDao carryPlanProductDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CarryPlanProduct queryById(Integer id) {
        return this.carryPlanProductDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param page 查询起始位置
     * @param pageSize 查询条数
     * @return 对象列表
     */

    public PageInfo<CarryPlanProduct> pageSelect(Integer parentid, int page, int pageSize){
        PageHelper.startPage(page,pageSize);
        List<CarryPlanProduct> findlist = this.carryPlanProductDao.queryAllByLimit(parentid);
        PageInfo<CarryPlanProduct> pageInfoUserList =  new PageInfo<CarryPlanProduct>(findlist);
        return pageInfoUserList;
    }

    /**
     * 新增数据
     *
     * @param carryPlanProduct 实例对象
     * @return 实例对象
     */
    @Override
    public CarryPlanProduct insert(CarryPlanProduct carryPlanProduct) {
        this.carryPlanProductDao.insert(carryPlanProduct);
        return carryPlanProduct;
    }

    /**
     * 修改数据
     *
     * @param carryPlanProduct 实例对象
     * @return 实例对象
     */
    @Override
    public CarryPlanProduct update(CarryPlanProduct carryPlanProduct) {
        this.carryPlanProductDao.update(carryPlanProduct);
        return this.queryById(carryPlanProduct.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id,Integer parentid) {
        return this.carryPlanProductDao.deleteById(id,parentid) > 0;
    }
}